#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

include /usr/share/quilt/quilt.make

export GCONF_DISABLE_MAKEFILE_SCHEMA_INSTALL=1
export QTDIR=/usr

PACKAGE = compiz

CFLAGS = -Wall -g
ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
	CFLAGS += -O0
else
	CFLAGS += -O2
endif
ifeq (,$(findstring nostrip,$(DEB_BUILD_OPTIONS)))
	INSTALL_PROGRAM += -s
endif

DEB_HOST_ARCH		?= $(shell dpkg-architecture -qDEB_HOST_ARCH)
DEB_HOST_GNU_TYPE	?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE	?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
ifeq ($(DEB_BUILD_GNU_TYPE), $(DEB_HOST_GNU_TYPE))
	confflags += --build=$(DEB_HOST_GNU_TYPE)
else
	confflags += --build=$(DEB_BUILD_GNU_TYPE) --host=$(DEB_HOST_GNU_TYPE)
endif

INSTALL = /usr/bin/install

# generated via:
#  python -c "import compizconfig; print ','.join(compizconfig.Context().Plugins['core'].Display['active_plugins'].Value)"
PLUGINS = core,dbus,place,move,resize,decoration,png,svg,imgjpeg,text,neg,video,wall,snap,animation,scale,expo,switcher,regex,resizeinfo,workarounds,ezoom,vpswitch,extrawm,fade,scaleaddon,scalefilter,session

confflags += --disable-static \
	     --disable-kde4 \
             --enable-librsvg \
             --enable-gconf-dump \
             --with-default-plugins="$(PLUGINS)"

build: patch build-stamp
build-stamp:
	dh_testdir
	mkdir obj-$(DEB_BUILD_GNU_TYPE)
	cd obj-$(DEB_BUILD_GNU_TYPE) && \
	../configure --prefix=/usr --sysconfdir=\$${prefix}/share $(confflags) \
	             CFLAGS="$(CFLAGS)"
	cd obj-$(DEB_BUILD_GNU_TYPE) && $(MAKE)
	(cd po; intltool-update -p --verbose)
	touch $@

prune:
	rm -f autogen.sh
	find -name .cvsignore | xargs rm -f
	rm -f po/*.gmo

clean: prune unpatch
	dh_testdir
	dh_testroot
	rm -f build-stamp
	
	rm -f config.cache config.log config.status
	rm -f */config.cache */config.log */config.status
	rm -f conftest* */conftest*
	rm -rf autom4te.cache */autom4te.cache
	rm -rf obj-*
	
	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_clean -k
	dh_installdirs

	cd obj-$(DEB_BUILD_GNU_TYPE) && $(MAKE) DESTDIR=$(CURDIR)/debian/tmp install

	mv $(CURDIR)/debian/tmp/usr/bin/compiz $(CURDIR)/debian/tmp/usr/bin/compiz.real
	$(INSTALL) --mode 0755 debian/compiz-manager $(CURDIR)/debian/tmp/usr/bin/compiz
	$(INSTALL) --mode 0755 debian/compiz-decorator $(CURDIR)/debian/tmp/usr/bin/
	mkdir -p $(CURDIR)/debian/tmp/etc/xdg/compiz
	$(INSTALL) --mode 0644 debian/compiz-manager.defaults $(CURDIR)/debian/tmp/etc/xdg/compiz/compiz-manager

	# remove unneeded .la files
	find $(CURDIR)/debian/tmp/usr/lib -type f -name '*.la' | xargs rm -f

	# create compiz keybidings file based on the metacity ones
	sed 's/wm_name=\"Metacity\" package=\"metacity\"/wm_name=\"compiz\" package=\"compiz\"/'  /usr/share/gnome-control-center/keybindings/50-metacity-desktop-key.xml > $(CURDIR)/debian/tmp/usr/share/gnome-control-center/keybindings/50-compiz-desktop-key.xml
	sed 's/wm_name=\"Metacity\" package=\"metacity\"/wm_name=\"compiz\" package=\"compiz\"/'  /usr/share/gnome-control-center/keybindings/50-metacity-key.xml > $(CURDIR)/debian/tmp/usr/share/gnome-control-center/keybindings/50-compiz-key.xml

	# add some selected keys
	sed -i -f debian/compiz-keybindings.sed $(CURDIR)/debian/tmp/usr/share/gnome-control-center/keybindings/50-compiz-desktop-key.xml

	# remove unsupported keys from compiz xml
	for unsupported in switch_group switch_panels cycle_windows cycle_group cycle_panels; do \
		sed -i "/metacity\/global_keybindings\/$$unsupported/d" $(CURDIR)/debian/tmp/usr/share/gnome-control-center/keybindings/50-compiz-key.xml; \
	done;


# Build architecture-dependent files here.
binary-arch: build install
	dh_testdir
	dh_testroot
	
	dh_installdocs
	dh_installchangelogs ChangeLog
	dh_install -pcompiz-plugins -Xlibkconfig.so -Xkconfig.xml -Xlibgconf.so -Xgconf.xml -Xcore.xml --sourcedir=debian/tmp
	dh_install -pcompiz-core --sourcedir=debian/tmp
	dh_install -pcompiz-dev --sourcedir=debian/tmp
	dh_install -pcompiz-gnome --sourcedir=debian/tmp
	dh_install -pcompiz-kde --sourcedir=debian/tmp
	dh_install -plibdecoration0 --sourcedir=debian/tmp
	dh_install -plibdecoration0-dev --sourcedir=debian/tmp
	dh_install -pcompiz --sourcedir=debian/tmp
	dh_installman
	dh_link
	dh_gconf
	dh_strip
	dh_compress
	dh_fixperms
	dh_makeshlibs
	dh_shlibdeps -L libdecoration0 -l debian/libdecoration0/usr/lib
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# Build architecture-independent files here.
binary-indep: build install
# Nothing to do

binary: binary-indep binary-arch
.PHONY: build clean binary-indep binary-arch binary install

